<template>
  <div>
    <el-dialog :title="click_title" :append-to-body="true" @close="closeDio" :visible="dialogTableVisible" width="1000px" class="cate-dio-box" style="padding: 20px">
      <el-tabs :stretch="true" v-model="activeName">
        <el-tab-pane :label="item" v-for="(item, j) in tabs" :key="j">
          <div class="fx" style="align-items: flex-start; margin-top: 35px; padding-bottom: 83px; margin-left: 35px">
            <div>
              <div v-for="(item, index) in shopsList" :key="index" class="box-menu" :style="{ display: activeName == 0 ? 'inline-block' : 'block', marginRight: activeName == 0 ? '60px' : '0' }">
                <p :style="{ marginBottom: activeName == 0 ? '0' : '24px' }" @click="addShops(item)">{{ item.title }}(一级)</p>
                <div v-if="activeName > 0">
                  <div v-if="item.z && isShopCate" class="box-menu-1">
                    <div v-for="(it, i) in item.z" :key="i" class="sa">
                      <p @click="addShops(it)">{{ it.title }} (二级)</p>
                      <span v-if="it.z && activeName == '2'" @click="showActive(it.id)" :style="{ color: active == it.id ? 'red' : '#ddd' }">[{{ active == it.id ? "-" : "+" }}]</span>
                      <!-- {{i%1}}{{i%2}}{{i%3}}{{i%4}} -->
                      <div
                        v-if="it.z"
                        class="box-menu-1"
                        style="width: 654px; background: #f9f9f9; margin-left: -20px; padding: 0 20px; left: 20px"
                        :style="{ marginTop: active == it.id ? '14px' : '0' }"
                      >
                        <div v-for="(its, is) in it.z" class="box-menu-2" :key="is" :class="{ activeMenu: active == its.parent_id }">
                          <p style="margin: 12px 0 12px" @click="addShops(its)">{{ its.title }} (三级)</p>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>
  </div>
</template>
<script>
import { mapState } from "vuex";
export default {
  name: "xzShopCate",
  props: {
    show: {
      type: Boolean,
      default: true,
    },
    showType: {
      type: String,
      default: "table",
    },
    isShopCate: {
      type: Boolean,
      default: true,
    },
    click_title: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      dialogTableVisible: this.show,
      loading: false,
      active: -1,
      activeName: 0,
      tabs: ["一级分类"],
    };
  },
  methods: {
    handleClick(tab, event) {
      console.log(tab, event);
    },
    toZhuanhuan(i) {
      if (i % 4) {
        return -((i % 4) * 152) + "px";
      }
    },
    showActive(id) {
      if (this.active == id) {
        this.active = -1;
      } else {
        this.active = id;
      }
    },
    addShops(row) {
      row.url_title = "产品分类";

      if (this.activeName == 0) {
        row.taburl = "/shop/cateimg?cate_id=" + row.id;
        row.activeName = "-样式一";
      } else if (this.activeName == 1) {
        row.taburl = "/shop/shopslide?cate_id=" + row.id;
        row.activeName = "-样式二";
      } else {
        row.taburl = "/shop/shopsearch?cate_id=" + row.id;
        row.activeName = " -样式三";
      }
      this.$emit("sendShop", row);
      this.closeDio();
    },

    closeDio() {
      this.$emit("isshow", false);
      this.dialogTableVisible = false;
    },
  },
  watch: {
    show(val1, val2) {
      if (val1 == val2) {
        return;
      }
      this.dialogTableVisible = val1;
      this.currentPage1 = 1;
    },
    dialogTableVisible(val1, val2) {
      if (val1 == val2) {
        return;
      }
      this.$emit("isshow", val1);
    },
    getMaterial(val) {
      this.shopsList = val;
      this.loading = false;
    },
  },
  computed: {
    ...mapState({
      shopsList: (state) => state.shopCateList,
    }),
    getMaterial() {
      return this.$store.state.shopCateList;
    },
  },
  create() {
    this.loading = true;
  },
};
</script>
<style lang="less" scoped>
.cate-phone {
  width: 326px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  position: relative;
  .cate-ts-text {
    position: absolute;
    bottom: -50px;
    left: 45px;
    p {
      padding: 10px 0;
      color: #c5c3c3;
    }
  }
  > div.cate-phone-bg {
    width: 176px;
    background: url("../../assets/img/config/phone-bg.png") no-repeat;
    background-size: 100% 100%;
    height: 360px;
    padding: 44px 12px;
    img {
      width: 150px;
      height: 270px;
    }
  }
}
.cate-phone + div {
  width: 653px;
}
.cate_product {
  display: flex;
  flex-wrap: wrap;
  > li {
    width: 100%;
    // height: 30px;
    line-height: 30px;
    cursor: pointer;
    margin-bottom: 13px;
    display: flex;

    p {
      width: 94px;
      background: #f6f6f6;
      border-radius: 5px;
    }
  }
  p:hover {
    color: red;
  }
}
.sa {
  margin-bottom: 24px;
}
.box-menu {
  margin-bottom: 24px;
  p {
    display: inline-block;
    min-width: 152px;
    padding: 0 10px;
    height: 42px;
    line-height: 42px;
    border-radius: 5px;
    background: #f5f5f5;
    text-align: center;
    // margin-bottom: 24px;
    cursor: pointer;
  }
  .disCate {
    background-color: #ddd;
  }
  span {
    color: #a3a3a3;
    margin-left: 12px;
    cursor: pointer;
  }
}
.box-menu-1 {
  display: flex;
  flex-wrap: wrap;
  position: relative;
  transition: all 0.3s linear;
  > div {
    width: 33%;
  }
}
.box-menu-2 {
  width: 712px;
  transition: all 0.3s linear;
  max-height: 0;
  overflow: hidden;
}
.activeMenu {
  max-height: 500px;
}
</style>
